﻿using Exam.DBHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.DAO.ExtendDAO
{
    public class MeetRoom
    {
        SQLHelper sqlhelper = new SQLHelper();
        public List<Exam.Model.ExtentionModels.ExMeetRoom> GetRoomList(string provinceid, string Cityid, string RoomName, string IsActive, string orderName, bool asc, int pagestart, int pagesize, out int totalcount)
        {
            StringBuilder builder = new StringBuilder("select  ProvinceName,CityName,room.* from (select * from MeetRoom  where 1=1 ");


            if (!string.IsNullOrEmpty(provinceid))
            {
                builder.Append(" and  ProvinceID='");
                builder.Append(provinceid);
                builder.Append("'");
            }
            if (!string.IsNullOrEmpty(Cityid))
            {
                builder.Append(" and CityID='");
                builder.Append(Cityid);
                builder.Append("'");
            }
            if (!string.IsNullOrEmpty(Cityid))
            {
                builder.Append(" and RoomName like N'%");
                builder.Append(RoomName);
                builder.Append("%'");
            }
            if (IsActive != "-1")
            {
                builder.Append(" and IsActive=");
                builder.Append(IsActive);
            }
            builder.Append(" ) room left join(select ProvinceName,CityID,CityName from Province  left join City  on Province.Provinceid=City.Provinceid) tb on  room.CityID=tb.CityID");

            if (!string.IsNullOrEmpty(orderName))
            {
                builder.Append(" order by ");
                builder.Append(orderName);
                if (asc)
                {
                    builder.Append(" asc");
                }
                else
                {
                    builder.Append(" desc");
                }
            }
            
            return sqlhelper.GetEntities<Model.ExtentionModels.ExMeetRoom>(builder.ToString(), pagestart, pagesize, out totalcount);

        }
    }
}
